<template>
<div class="content">
    <div><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1564654436156&di=5d43b4263c396ee83a929b07ec28f3b6&imgtype=0&src=http%3A%2F%2Fd.ifengimg.com%2Fw600%2Fe0.ifengimg.com%2F08%2F2018%2F1222%2FDFBD4C92AFEB21B8BF27B15C6EF369422960B781_size40_w640_h396.jpeg"></div>
    <form class="mui-input-group">
    <div class="mui-input-row">
        <label>用户名</label>
    <input type="text" class="mui-input-clear" placeholder="请输入用户名" v-model="name">
    </div>
    <div class="mui-input-row">
        <label>密码</label>
        <input type="password" class="mui-input-password" placeholder="请输入密码" v-model="pwd">
    </div>
    <div class="mui-button-row">
        <button type="button" class="mui-btn mui-btn-primary" @click="login">确认</button>
        <button type="button" class="mui-btn mui-btn-danger" @click="change">注册</button>
    </div>
    </form>
</div>
</template>
<script>
import mui from'../../../lib/MUI/js/mui.min.js'
import { Toast } from 'mint-ui';
export default {
    data(){
        return{
            name:"",
            pwd:"",
            number:"",
            username:""
        }
    },
    methods:{
        change(){
            this.$router.push({name:"regist"})
        },
        login(){
            if(!this.name||!this.pwd)
            {
                Toast('请填写以上内容');
                this.name="";
                this.pwd="";
            }
            else{
                this.$http.post('http://192.168.0.197:88/login',{name:this.name,pwd:this.pwd},{emulateJSON:true}).then(function(res){
                console.log(res.body.data);
                Toast(res.body.data);
                if(res.body.data!="登入用户名或密码错误")
                    {
                        this.$router.push({name:'myinfo'})                       
                        window.localStorage.setItem('usernumber',res.body.data.id)
                        window.localStorage.setItem('userName',this.name)
                        Toast('登录成功')                  
                    }
                },function(res){
                    console.log(res.status);
                
                });
                
            }
        },
    },
    watch: {
            "username"() {
                     if(this.username)
                    {
                        this.$router.push("/vip/myinfo")
                    }
                    else{
                        this.$router.push("/vip")
                    }
			}
        },
    created(){			
          this.username=window.localStorage.getItem('userName')
          console.log(this.username)
		}
}
</script>
<style scoped>
   img{
       width:100%;
       height: 200px;
   }
</style>